/********************************* TODO: New client panel look? More input on ClientCmd config? *****************************************/

include( "gadcfg.lua" )

if ( CLIENT ) then

function panel()
local frame = vgui.Create( "DFrame" )
local sheet = vgui.Create( "DPropertySheet" , frame )

local framex = 700
local framey = 450

	frame:SetPos(1000-framex,900-framey)
	frame:SetSize( framex , framey )
	frame:SetTitle( mod.Name .. " Main Menu" )
	frame:MakePopup()
	frame.Paint = function() draw.RoundedBox(3,0,0,frame:GetWide(),frame:GetTall(),Color(0,0,0,200)) end
	
	sheet:SetPos(10,30)
	sheet:SetSize( framex-20 , framey-75 )

/************************************************************* MAP PANEL*********************************************************************/
local map = vgui.Create( "DPanel", sheet)
local dynmap = vgui.Create( "DPanel", map)
local statmap = vgui.Create( "DPanel", map)
local mapview = vgui.Create( "DMultiChoice", map)

map:SetPos(-10,-10)
map:SetSize(sheet:GetWide()+10,sheet:GetTall()+10)

dynmap:SetPos(0,0)
dynmap:SetSize(sheet:GetWide()-10,sheet:GetTall()-85)
dynmap.Paint = function()
	surface.SetDrawColor(50,50,50,255)
     	surface.DrawRect(0,0,dynmap:GetWide(),dynmap:GetTall())
end
statmap:SetPos(0,sheet:GetTall()-80)
statmap:SetSize(sheet:GetWide()-10,83)
statmap.Paint = function()
	surface.SetDrawColor(50,50,50,255)
     	surface.DrawRect(0,0,statmap:GetWide(),statmap:GetTall())
end

-- Make the Timer Slider --
local mapslider = vgui.Create( "DNumSlider",map)
mapslider:SetPos(440,sheet:GetTall()-75)
mapslider:SetSize(200,40)
mapslider:SetText( "Time Delay (secs)")
mapslider:SetMin(0)
mapslider:SetMax(1200)
mapslider:SetDecimals(0)

-- Make the Gamemode button -- 
local switchbtn = vgui.Create( "DButton" ,map)
switchbtn:SetText( "Gamemode: <default>" )
switchbtn:SetPos(sheet:GetWide()/2-65-string.len(switchbtn:GetValue())*2-10,sheet:GetTall()-70)
switchbtn:SetSize(90+string.len(switchbtn:GetValue())*4-10,30)
switchbtn.DoClick = function()
	local menu = DermaMenu()
	menu:AddOption( "<default>" ,function() switchbtn:SetText( "Gamemode: <default>" )
		switchbtn:SetPos(sheet:GetWide()/2-65-string.len(switchbtn:GetValue())*2-10,sheet:GetTall()-70)
		switchbtn:SetSize(90+string.len(switchbtn:GetValue())*4-10,30) end)
	for _, dir in ipairs(mod.Gamemodes) do
		if file.Exists( "../gamemodes/" .. dir .. "/info.txt" ) then
			menu:AddOption(dir,function() switchbtn:SetText( "Gamemode: " ..dir) 
			switchbtn:SetPos(sheet:GetWide()/2-65-string.len(switchbtn:GetValue())*2-10,sheet:GetTall()-70)
			switchbtn:SetSize(90+string.len(switchbtn:GetValue())*4-10,30)end) end 
	end
	menu:Open()
end

-- Make the panel --
local mappanel = vgui.Create( "DPanelList",map)
mappanel:SetPos(0,0)
mappanel:SetSize(dynmap:GetWide(),dynmap:GetTall())
mappanel.Paint = function()
	surface.SetDrawColor(50,50,50,255)
     	surface.DrawRect(0,0,mappanel:GetWide(),mappanel:GetTall())
end
mappanel:EnableVerticalScrollbar(true)
mappanel:EnableHorizontal(true)
mappanel:SetSpacing(5)
mappanel:SetPadding(8)

-- Make the buttons--
function MakeMapButton(text)
	local btn = vgui.Create( "DButton" ,mappanel)
	btn:SetSize(mappanel:GetWide()/5-10,20)
	btn:SetText(text)
	btn.DoClick = function()
		if !LocalPlayer():IsAdmin() then LocalPlayer():ChatPrint( "Must be admin!") return end
		local gamemode = string.Right(switchbtn:GetValue(),string.len(switchbtn:GetValue())-10)
		if mapslider:GetValue() != 0 then LocalPlayer():ChatPrint( "Map timer created for "..mapslider:GetValue().. " seconds.")
			timer.Create( "MapTimer",mapslider:GetValue(),1,function()
				if string.lower(mod.Name) == "ulx" then RunConsoleCommand( "ulx", "map", "lolz") 
					if gamemode != "<default>" then RunConsoleCommand( "ulx", "map", text, gamemode)
					else RunConsoleCommand( "ulx", "map",text) end
				else 
					if gamemode != "<default>" then RunConsoleCommand( "gad_rcon", "sv_defaultgamemode",gamemode) end
					RunConsoleCommand( mod.MapCmd, text )
				end
			end)
		else
			if string.lower(mod.Name) == "ulx" then RunConsoleCommand( "ulx", "map", "lolz") 
				if gamemode != "<default>" then RunConsoleCommand( "ulx", "map", text, gamemode)
				else RunConsoleCommand( "ulx", "map",text) end
			else 
				if gamemode != "<default>" then RunConsoleCommand( "gad_rcon", "sv_defaultgamemode",gamemode) end
				RunConsoleCommand( mod.MapCmd, text )
			end
		end
	end
	return btn
end

for _,v in ipairs(mod.Maps) do mappanel:AddItem(MakeMapButton(v)) end

-- Map List --
local mapbox = vgui.Create( "DComboBox", map)
local maptext = vgui.Create( "DTextEntry", map)
local mapviewbtn = vgui.Create( "DButton", map)
mapbox:SetPos(0,0)
mapbox:SetSize(sheet:GetWide()/4+20,sheet:GetTall()-85)
mapbox:SetMultiple(false)
for k,v in ipairs(mod.Maps) do 
	mapbox:AddItem(v) 
	if k == 1 then mapbox:SelectByName(v) end 
end

-- Filter Text --
maptext:SetPos(sheet:GetWide()/4+45,255)
maptext:SetSize(200,25)
maptext.OnTextChanged = function() 
	mapbox:Clear()
	for _,v in ipairs(mod.Maps) do
		if string.match(v,maptext:GetValue()) then mapbox:AddItem(v) end
	end
end
local maptextlabel = vgui.Create( "DLabel",map)
maptextlabel:SetPos(sheet:GetWide()/4+120,237)
maptextlabel:SetTextColor(Color(255,255,255,255))
maptextlabel:SetText( "Filter Text")

-- Change Map Button --
mapviewbtn:SetPos(sheet:GetWide()/1.5-15,255)
mapviewbtn:SetSize(200,25)
mapviewbtn:SetTextColor(Color(0,0,0,255),Color(255,255,255,255))
mapviewbtn:SetText( "Change Map" )
mapviewbtn.DoClick = function()
	if !LocalPlayer():IsAdmin() then LocalPlayer():ChatPrint( "Must be admin!") return end
	local gamemode = string.Right(switchbtn:GetValue(),string.len(switchbtn:GetValue())-10)
	if mapslider:GetValue() != 0 then LocalPlayer():ChatPrint( "Map timer created for "..mapslider:GetValue().. " seconds.")
		timer.Create( "MapTimer",mapslider:GetValue(),1,function()
			if string.lower(mod.Name) == "ulx" then RunConsoleCommand( "ulx", "map",mapbox:GetSelected():GetValue()) 
				if gamemode != "<default>" then RunConsoleCommand( "ulx", "map", mapbox:GetSelected():GetValue(), gamemode)
				else RunConsoleCommand( "ulx", "map",mapbox:GetSelected():GetValue()) end
			else 
				if gamemode != "<default>" then RunConsoleCommand( "gad_rcon", "sv_defaultgamemode",gamemode) end
				RunConsoleCommand( mod.MapCmd, mapbox:GetSelected():GetValue() )
			end
		end)
	else
		if string.lower(mod.Name) == "ulx" then RunConsoleCommand( "ulx", "map",mapbox:GetSelected():GetValue()) 
			if gamemode != "<default>" then RunConsoleCommand( "ulx", "map", mapbox:GetSelected():GetValue(), gamemode)
			else RunConsoleCommand( "ulx", "map",mapbox:GetSelected():GetValue()) end
		else 
			if gamemode != "<default>" then RunConsoleCommand( "gad_rcon", "sv_defaultgamemode",gamemode) end
			RunConsoleCommand( mod.MapCmd, mapbox:GetSelected():GetValue() )
		end
	end
end

-- Map Image --
mapimg = vgui.Create( "DImage", map)
mapimg:SetPos(sheet:GetWide()/4+60,30)
mapimg:SetSize(sheet:GetWide()-sheet:GetWide()/4-110,sheet:GetTall()-180)
mapimg.Think = function()
if mapbox:GetSelected():IsValid() and file.Exists( "../materials/maps/"..mapbox:GetSelected():GetValue().. ".vtf") then
	mapimg:SetImage( "maps/"..mapbox:GetSelected():GetValue()) 
else mapimg:SetImage( "vgui/swepicon")
end
end

-- View Changer --
CreateClientConVar( "mapmenutype", "List View", false, false)
mapview:SetPos(40,sheet:GetTall()-66)
mapview:AddChoice( "List View")
mapview:AddChoice( "Button View")
mapview:SetSize(120,20)
mapview:SetEditable(false)
mapview:SetConVar( "mapmenutype")
mapview.Think = function()
	if GetConVarString( "mapmenutype") == "List View" then
		mappanel:SetVisible(false)
		mapbox:SetVisible(true)
		maptext:SetVisible(true)
		mapviewbtn:SetVisible(true)
		mapimg:SetVisible(true)
		maptextlabel:SetVisible(true)
	elseif GetConVarString( "mapmenutype") == "Button View" then
		mappanel:SetVisible(true)
		mapbox:SetVisible(false)
		maptext:SetVisible(false)
		mapviewbtn:SetVisible(false)
		mapimg:SetVisible(false)
		maptextlabel:SetVisible(false)
	end
end

/************************************************************* CLIENT PANEL ***********************************************************************/
clientpanel = vgui.Create( "DPanel" ,sheet)
plylist = vgui.Create( "DComboBox" ,clientpanel)
serverpanel = vgui.Create( "DPanelList" ,clientpanel)
funpanel = vgui.Create( "DPanel" ,clientpanel)
funpanellist = vgui.Create( "DPanelList", clientpanel)

-- Make the panels --
clientpanel:SetPos(0,0)
clientpanel:SetSize(sheet:GetWide(),sheet:GetTall())

plylist:SetPos(0,0)
plylist:SetSize(150,clientpanel:GetTall()-60)
for k, v in ipairs(player.GetAll()) do
	plylist:AddItem(v:Nick()) 
	if k == 1 then plylist:SelectByName(v:Nick()) end
end


/************************************ MODEL PANEL ************************************/

local ModelWindow = vgui.Create( "DPanel",clientpanel)
ModelWindow:SetPos(155,0)
ModelWindow:SetSize(clientpanel:GetWide()-165,clientpanel:GetTall())
ModelWindow.Paint = function()
	surface.SetDrawColor(50,50,50,255)
     	surface.DrawRect(0,0,ModelWindow:GetWide(),ModelWindow:GetTall())
end

local mdlPanel = vgui.Create( "DModelPanel", ModelWindow )
mdlPanel:SetSize( 220, 220 )
mdlPanel:SetPos( 15, 50 )
mdlPanel:SetModel( "models/player/police.mdl" )
mdlPanel:SetAnimSpeed( 0.0 )
mdlPanel:SetAnimated( false )
mdlPanel:SetAmbientLight( Color( 50, 50, 50 ) )
mdlPanel:SetDirectionalLight( BOX_TOP, Color( 255, 255, 255 ) )
mdlPanel:SetDirectionalLight( BOX_FRONT, Color( 255, 255, 255 ) )
mdlPanel:SetCamPos( Vector( 50, 0, 50 ) )
mdlPanel:SetLookAt( Vector( 0, 0, 51 ) )
mdlPanel:SetFOV( 60 )

local angslider = vgui.Create( "DNumSlider",ModelWindow)
angslider:SetPos(20,ModelWindow:GetTall()-90)
angslider:SetSize(230,40)
angslider:SetText( "Angle")
angslider:SetMin(0)
angslider:SetMax(360)

CreateClientConVar( "mdlpanel", "Combine")
mdlnum = 1
local models = mod.Models[1][2]
local mdlchoice = vgui.Create( "DMultiChoice",ModelWindow)
mdlchoice:SetEditable(false)
mdlchoice:SetPos(62,13)
mdlchoice:SetSize(125,20)
for _,v in ipairs(mod.Models) do mdlchoice:AddChoice(v[1]) end
mdlchoice:SetConVar( "mdlpanel")
cvars.AddChangeCallback( "mdlpanel",function()
	for _,v in ipairs(mod.Models) do
		if GetConVarString( "mdlpanel") == v[1] then 
			models = v[2] 
			mdlPanel:SetModel(models[1])
			mdlnum = 1
			return 
		end
	end
end)
mdlchoice:ChooseOptionID(1)

function CreateSwitchMdlBtn(pos,inc)
	local btn = vgui.Create( "DSysButton",ModelWindow)
	btn:SetPos(pos[1],pos[2])
	btn:SetSize(20,20)
	btn:SetChar( "LOL?")
	if inc == true then
		btn:SetType( "right")
		btn.DoClick = function()
			mdlnum = mdlnum + 1
			if mdlnum > table.Count(models) then mdlnum = 1 end
			mdlPanel:SetModel(models[mdlnum])
		end
	else
		btn:SetType( "left")
		btn.DoClick = function()
			mdlnum = mdlnum - 1
			if mdlnum < 1 then mdlnum = table.Count(models) end
			mdlPanel:SetModel(models[mdlnum])
		end
	end
end
CreateSwitchMdlBtn({240,120},true)
CreateSwitchMdlBtn({240,150},false)

CreateClientConVar( "gad_mdl", "")
local setmdlbtn = vgui.Create( "DButton",ModelWindow)
setmdlbtn:SetPos(320,30)
setmdlbtn:SetSize(150,30)
setmdlbtn:SetText( "Set Player Model")
setmdlbtn.DoClick = function()
	if not LocalPlayer():IsAdmin() then LocalPlayer():ChatPrint( "Must be admin!") return
	elseif not plylist:GetSelectedItems() or table.Count(plylist:GetSelectedItems()) > 1 then return end

	local name = string.Explode( " ",plylist:GetSelectedItems()[1]:GetValue())
	RunConsoleCommand( "gad_setmdl",name[table.Count(name)])
end
setmdlbtn.Think = function() RunConsoleCommand( "gad_mdl",models[mdlnum]) end

CreateClientConVar( "gad_Red",255)
CreateClientConVar( "gad_Green",255)
CreateClientConVar( "gad_Blue",255)
CreateClientConVar( "gad_Alpha",255)
function CreateColorSlider(pos,type)
	local slider = vgui.Create( "DNumSlider",ModelWindow)
	slider:SetPos(pos[1],pos[2])
	slider:SetSize(150,40)
	slider:SetText(type)
	slider:SetMin(0)
	slider:SetMax(255)
	slider:SetDecimals(0)
	slider:SetValue(255)
	slider:SetConVar( "gad_"..type)
end

CreateColorSlider({320,90}, "Red")
CreateColorSlider({320,130}, "Green")
CreateColorSlider({320,170}, "Blue")
CreateColorSlider({320,210}, "Alpha")

local setcolbtn = vgui.Create( "DButton",ModelWindow)
setcolbtn:SetPos(320,280)
setcolbtn:SetSize(150,30)
setcolbtn:SetText( "Set Player Color")
setcolbtn.DoClick = function()
	if not LocalPlayer():IsAdmin() then LocalPlayer():ChatPrint( "Must be admin!") return
	elseif not plylist:GetSelectedItems() or table.Count(plylist:GetSelectedItems()) > 1 then return end

	local name = string.Explode( " ",plylist:GetSelectedItems()[1]:GetValue())
	RunConsoleCommand( "gad_setcol",name[table.Count(name)])
end
setcolbtn.Think = function()
	mdlPanel:SetColor(Color(GetConVarNumber( "gad_Red"),GetConVarNumber( "gad_Green"),GetConVarNumber( "gad_Blue"),GetConVarNumber( "gad_Alpha"))) 
end

local mdlbtn = vgui.Create( "DSysButton",clientpanel)
mdlbtn:SetPos(5,clientpanel:GetTall()-55)
mdlbtn:SetSize(20,20)
mdlbtn:SetType( "right")
mdlbtn.DoClick = function()
	if mdlbtn:GetType() == "right" then
		funpanel:SetVisible(false)
		serverpanel:SetVisible(false)
		ModelWindow:SetVisible(true)
		funchoice:SetVisible(false)
		mdlbtn:SetType( "left")
	else
		funpanel:SetVisible(true)
		serverpanel:SetVisible(true)
		ModelWindow:SetVisible(false)
		funchoice:SetVisible(true)
		mdlbtn:SetType( "right")
	end
end

mdlbtnlabel = vgui.Create( "DLabel",clientpanel)
mdlbtnlabel:SetPos(45,sheet:GetTall()-55)
mdlbtnlabel:SetSize(200,20)
mdlbtnlabel:SetText( "To Model Panel")
mdlbtnlabel:SetTextColor(Color(0,0,0,255))
mdlbtnlabel.Think = function()
	if ModelWindow:IsVisible() == true then mdlbtnlabel:SetText( "To Client Panel")
	else mdlbtnlabel:SetText( "To Model Panel") end
end

function mdlPanel:LayoutEntity(Entity)
	self:RunAnimation();
	Entity:SetAngles( Angle( 0, angslider:GetValue(), 0) )		
end
ModelWindow:SetVisible(false)

/******************************************* SERVER/CLIENT PANEL *******************************************/

serverpanel:SetPos(plylist:GetWide()+5,0)
serverpanel:SetSize(85,clientpanel:GetTall())
serverpanel.Paint = function()
	surface.SetDrawColor(50,50,50,255)
      surface.DrawRect(0,0,serverpanel:GetWide(),serverpanel:GetTall())
end
serverpanel:EnableVerticalScrollbar(true)
serverpanel:SetPadding(8)
serverpanel:SetSpacing(10)

funpanel:SetPos(plylist:GetWide()+serverpanel:GetWide()+10,0)
funpanel:SetSize(clientpanel:GetWide()-plylist:GetWide()-serverpanel:GetWide()-5,clientpanel:GetTall())
funpanel.Paint = function()
	surface.SetDrawColor(50,50,50,255)
      surface.DrawRect(0,0,funpanel:GetWide(),funpanel:GetTall())
end
/*funpanel:EnableVerticalScrollbar(true)
funpanel:EnableHorizontal(true)
funpanel:SetPadding(8)
funpanel:SetSpacing(8)*/

funpanellist:SetPos(plylist:GetWide()+serverpanel:GetWide()+10,0)
funpanellist:SetSize(clientpanel:GetWide()-plylist:GetWide()-serverpanel:GetWide()-5,clientpanel:GetTall())
funpanellist.Paint = function()
	surface.SetDrawColor(50,50,50,255)
      surface.DrawRect(0,0,funpanellist:GetWide(),funpanellist:GetTall())
end
funpanellist:EnableVerticalScrollbar(true)
funpanellist:EnableHorizontal(true)
funpanellist:SetPadding(8)
funpanellist:SetSpacing(8)
funpanellist:SetVisible(false)

function RunClientCmd(args) 
	local name = string.Explode( " ",plylist:GetSelectedItems()[1]:GetValue())
	if type(args) != "table" then Msg( "Not a table!\n" ) return end
	for k,v in ipairs(plylist:GetSelectedItems()) do
		if string.lower(mod.Name) == "ulx" then RunConsoleCommand( "ulx",args[1],v:GetValue(),args[2],args[3])
		elseif string.lower(mod.Name) == "ss" then RunConsoleCommand("ss",args[1],v:GetValue(),args[2],args[3])
		else RunConsoleCommand(args[1],name[table.Count(name)],args[2],args[3]) end
	end
end

local num = {10,20,30,40,50,60,70,80,90,100}
local temp = {5,15,30,60,120,240}
local clslider = vgui.Create("DNumSlider",funpanel)
clslider:SetPos(5,funpanel:GetTall()-70)
clslider:SetSize(funpanel:GetWide()-30,35)
clslider:SetText("Buttons")
clslider:SetMax(98*table.Count(mod.ClientCmds))
clslider:SetValue(98*table.Count(mod.ClientCmds))

-- Make the buttons --
function MakeClientButton(text,cmd,size,order,fancy,image,parent)
	local btn = vgui.Create( "DButton",parent)
	btn:SetSize(size[1],size[2])
	btn:SetText(text)
	btn.DoClick = function() 
		if !LocalPlayer():IsAdmin() and text != "Info" then LocalPlayer():ChatPrint( "Must be admin!") return end
		if text == "Give Health" or text == "Give Armor" then
			local btnmenu = DermaMenu()
			for k,v in ipairs(num) do btnmenu:AddOption(tostring(v),function() RunClientCmd({cmd[1],v}) end) end
			btnmenu:Open()
		elseif text == "Take Health" or text == "Take Armor" then
			local btnmenu = DermaMenu()
			for k,v in ipairs(num) do btnmenu:AddOption(tostring(v),function() RunClientCmd({cmd[1],-v}) end) end
			btnmenu:Open()
		elseif text == "Set Access" then
			local btnmenu = DermaMenu()
			//btnmenu:AddOption( "Guest" ,function() RunClientCmd({cmd[1],5}) end)
			//btnmenu:AddOption( "Respected" ,function() RunClientCmd({cmd[1],4}) end)
			if string.lower(mod.Name) == "ulx" then
				btnmenu:AddOption( "Admin" ,function() RunClientCmd({cmd[1], "admin"}) end)
				btnmenu:AddOption( "Super Admin" ,function() RunClientCmd({cmd[1], "superadmin"}) end)
			elseif string.lower(mod.Name) == "assmod" then
				btnmenu:AddOption( "Admin" ,function() RunClientCmd({cmd[1],2}) end)
				btnmenu:AddOption( "Super Admin" ,function() RunClientCmd({cmd[1],1}) end)
			end
			btnmenu:Open()
		elseif text == "Info" then
			if not plylist:GetSelectedItems() or table.Count(plylist:GetSelectedItems()) > 1 then return end
			for _,v in ipairs(player.GetAll()) do if v:Nick() == plylist:GetSelectedItems()[1]:GetValue() then ply = v end end
			local info = vgui.Create( "DFrame" )
			info:SetSize(200,400)
			info:Center()
			info:SetTitle( "Player Info" )
			info:SetVisible(true)
			info:MakePopup()

			local infolist = vgui.Create( "DListView" ,info)
			infolist:SetPos(10,30)
			infolist:SetSize(info:GetWide()-20,info:GetTall()-220)
			infolist:AddColumn( "Key" )
			infolist:AddColumn( "Value" )
			
			local infos = {
			{ "Name",ply:Nick()},
			{ "Team",team.GetName(ply:Team())},
			{ "Model",string.Explode( "/",ply:GetModel())[table.Count(string.Explode( "/",ply:GetModel()))]},
			{ "Health",ply:Health()},
			{ "Armor",ply:Armor()},
			{ "Position", "["..math.Round(ply:GetPos().x).. ","..math.Round(ply:GetPos().y).. ","..math.Round(ply:GetPos().z).. "]"},
			{ "Velocity",math.Round(ply:GetVelocity():Length()/17.6)},
			{ "Frags",ply:Frags()},
			{ "Deaths",ply:Deaths()}
			}

			for _,v in ipairs(infos) do
				infolist:AddLine(v[1].. ":",v[2])
			end

			local serverlist = vgui.Create( "DListView" ,info)
			serverlist:SetPos(10,infolist:GetTall()+50)
			serverlist:SetSize(info:GetWide()-20,info:GetTall()-infolist:GetTall()-70)
			serverlist:AddColumn( "Key" )
			serverlist:AddColumn( "Value" )
			
			local servers = {
			{ "Name", GetConVarString( "hostname")},
			{ "Map", GetConVarString( "host_map")},
			{ "Gamemode", gmod.GetGamemode().Name},
			{ "Num. Players", table.Count(player.GetAll()).. "/"..MaxPlayers()}
			}
		
			for _,v in ipairs(servers) do
				serverlist:AddLine(v[1].. ":",v[2])
			end
		elseif text == "Give Weapon" then
			local btnmenu = DermaMenu()
			for _,v in ipairs(mod.Weapons) do 
				if v.PrintName then btnmenu:AddOption(v.PrintName,function() RunClientCmd({ "gad_givewep",v.ClassName}) end) end
			end
			btnmenu:Open()
		else
			RunClientCmd(cmd)
		end
	end
	if fancy == true then
		btn.Think = function()
			btnpos = 100*order+clslider:GetValue()-100*table.Count(mod.ClientCmds)+200
			btn:SetPos(btnpos-50,250-math.abs((funpanel:GetWide())/2-btnpos)/3)
			//btn:SetSize(120-math.abs((btnpos-frame:GetWide()/2)/frame:GetWide())*100,25)
			//newsize = bigsize-math.abs(positionofbutton-middleofscreen)/widthofscreen)*(bigsize-smallsize)
			btn:SetSize(150-math.abs((funpanel:GetWide())/1.3-btnpos)/3-math.abs((funpanel:GetWide())/2.9-btnpos)/3,40-math.abs((funpanel:GetWide())/2.9-btnpos)/10)
		end
		local img = vgui.Create("DImage",funpanel)
		img.Think = function()
			img:SetPos(btnpos-80,80-math.abs((funpanel:GetWide())/2-btnpos))
			img:SetSize(150-math.abs((funpanel:GetWide())/2-btnpos),150-math.abs((funpanel:GetWide())/2-btnpos))
		end
		if image then img:SetImage(image) else img:SetImage("vgui/swepicon") end
	end
	return btn
end

-- Make all the pretty buttons show up
/* for k,v in ipairs(mod.ClientCmds) do
	funpanel:AddItem(MakeClientButton(v[1],v[2],{funpanel:GetWide()/5-13,35})) -- 67
end */



for k,v in ipairs(mod.ClientCmds) do
	MakeClientButton(v[1],v[2],{75,25},k,true,v[3],funpanel)
	funpanellist:AddItem(MakeClientButton(v[1],v[2],{75,25},k,false,v[3],funpanellist))
end

for k,v in ipairs(mod.ServerCmds) do
	serverpanel:AddItem(MakeClientButton(v[1],v[2],{75,38}))
end

CreateClientConVar("funchoice","Scroll View")
funchoice = vgui.Create( "DMultiChoice", clientpanel)
funchoice:SetPos(clientpanel:GetWide()/2+70,295)
funchoice:SetSize(90,20)
funchoice:SetEditable(false)
funchoice:AddChoice("Scroll View")
funchoice:AddChoice("Button View")
funchoice:ChooseOptionID(1)
funchoice:SetConVar( "funchoice")

funchoice.Think = function()
	if GetConVarString("funchoice") == "Scroll View" then
		funpanel:SetVisible(true)
		funpanellist:SetVisible(false)
	else
		funpanel:SetVisible(false)
		funpanellist:SetVisible(true)
	end
end

/************************************************************* ADMIN PANEL ***********************************************************************/

-- Make the panels --
local adminpanel = vgui.Create( "DPanel" ,sheet)
local btnpanel = vgui.Create( "DPanelList" ,adminpanel)
local sliderpanel = vgui.Create( "DPanelList" ,adminpanel)
local apply = vgui.Create( "DButton" ,adminpanel)

	btnpanel:SetPos(0,0)
	btnpanel:SetSize(150,sheet:GetTall())
	btnpanel.Paint = function()
		surface.SetDrawColor(50,50,50,255)
      	surface.DrawRect(0,0,btnpanel:GetWide(),btnpanel:GetTall())
	end
	btnpanel:EnableVerticalScrollbar(true)
	btnpanel:SetSpacing(5)
	btnpanel:SetPadding(6)

	sliderpanel:SetPos(160,0)
	sliderpanel:SetSize(sheet:GetWide()-180,sheet:GetTall()-90)
	sliderpanel.Paint = function()
		surface.SetDrawColor(50,50,50,255)
      	surface.DrawRect(0,0,sliderpanel:GetWide(),sliderpanel:GetTall())
	end
	sliderpanel:EnableVerticalScrollbar(true)
	sliderpanel:EnableHorizontal(true)
	sliderpanel:SetSpacing(10)
	sliderpanel:SetPadding(10)
	
	apply:SetPos(sheet:GetWide()-325,sheet:GetTall()-75)
	apply:SetSize(100,30)
	apply:SetText( "Apply" )
	changedvars = {}
	apply.DoClick = function()
		if !LocalPlayer():IsSuperAdmin() then LocalPlayer():ChatPrint( "Must be super admin!") return end
		for k,v in pairs(sliderpanel:GetItems()) do
			for p,q in pairs(changedvars) do
				if q.str == v:GetName() then if v:GetValue() != q.n then RunConsoleCommand( "gad_rcon",q.con,tostring(v:GetValue())) end end
			end
		end
	end

-- Make the buttons --
function MakeAdminButton(text,cmd)
	local btn = vgui.Create( "DButton" ,btnpanel)
	if GetConVarNumber(cmd) > 0 then btn:SetText( "Disable " ..text)
	else btn:SetText( "Enable " ..text) end
	btn.DoClick = function() 
		if !LocalPlayer():IsSuperAdmin() then LocalPlayer():ChatPrint( "Must be super admin!") return end
		if text == "Password" then
			if GetConVarString(cmd) == "" then
				local txtframe = vgui.Create( "DFrame")
				txtframe:SetSize(220,55)
				txtframe:Center() 
				txtframe:MakePopup()
				txtframe:SetTitle( "Set Password")
				local pswd = vgui.Create( "DTextEntry",txtframe)
				pswd:SetPos(7,30)
				pswd:SetSize(205,20)
				pswd:SetEditable(true)
				pswd.OnEnter = function()
					RunConsoleCommand( "gad_rcon",cmd,pswd:GetValue())
					txtframe:Close()
				end 
				btn:SetText( "Disable "..text)
			else RunConsoleCommand( "gad_rcon",cmd, "")
				btn:SetText( "Disable "..text) end
			return
		end
		if GetConVarNumber(cmd) > 0 then btn:SetText( "Enable " ..text)
			RunConsoleCommand( "gad_rcon",cmd, "0" )
		else btn:SetText( "Disable " ..text)
			RunConsoleCommand( "gad_rcon",cmd, "1" )
		end
	end
	//btn.Paint  = function() draw.RoundedBox(3,0,0,btn:GetWide(),btn:GetTall(),Color(150,0,0,255)) end
	//btn.OnMousePressed = function() draw.RoundedBox(3,4,4,btn:GetWide(),btn:GetTall(),Color(0,0,150,255)) end
	//btn.OnMouseReleased = function() draw.RoundedBox(3,0,0,btn:GetWide(),btn:GetTall(),Color(150,0,0,255)) end
	return btn
end

for k,v in ipairs(mod.Convars) do
	btnpanel:AddItem(MakeAdminButton(v[1],v[2]))
end


-- Make the sliders --
function MakeSlider(text,cmd,value)
	local slider = vgui.Create( "DNumSlider" ,sliderpanel)
	slider:SetText(text)
	slider:SetSize(sliderpanel:GetWide()/2-25,45)
	slider:SetDecimals(0)
	slider:SetMin(0)
	slider:SetMax(255)
	if GetConVarString(cmd) == "" then slider:SetValue(value)
		table.insert(changedvars,{n = value,str = text,con=cmd})
		if mod.AutoLimitConVars == 1 then RunConsoleCommand( "gad_rcon",cmd,tostring(value)) end
	else slider:SetValue(GetConVarNumber(cmd))
		table.insert(changedvars,{n = GetConVarNumber(cmd),str = text,con=cmd})
	end
	slider:SetName(text)
	return slider
end

for k,v in ipairs(mod.Sandboxvars) do
	sliderpanel:AddItem(MakeSlider(v.text,v.var,v.val))
end



/****************************************************************** FILE BROWSING *****************************************************************/
local treepanel = vgui.Create( "DPanel", sheet)
treepanel:SetPos(0,0)
treepanel:SetSize(sheet:GetWide(),sheet:GetTall())

local tree = vgui.Create( "DTree",treepanel)
tree:SetPos(0,0)
tree:SetSize(200,treepanel:GetTall()-30)
local sounds = {}

local filepanels = {}

local mdlpanel = vgui.Create( "DPanel",treepanel)
mdlpanel:SetPos(320,5)
mdlpanel:SetSize(treepanel:GetWide()-335,treepanel:GetTall()-40)
mdlpanel.Paint = function()
	surface.SetDrawColor(50,50,50,255)
     	surface.DrawRect(0,0,mdlpanel:GetWide(),mdlpanel:GetTall()) 
end
table.insert(filepanels,mdlpanel)

local mdl = vgui.Create( "DImage",mdlpanel)
mdl:SetPos(0,0)
mdl:SetSize(mdlpanel:GetWide(),mdlpanel:GetTall() )
mdl:SetImage( "console/gmod_logo")
table.insert(filepanels,mdl)

local mdlviewer = vgui.Create( "DModelPanel", mdlpanel)
mdlviewer:SetSize( mdlpanel:GetWide(), mdlpanel:GetTall() )
mdlviewer:SetPos( 0,0 )
mdlviewer:SetAnimSpeed( 0.0 )
mdlviewer:SetAnimated( false )
mdlviewer:SetAmbientLight( Color( 50, 50, 50 ) )
mdlviewer:SetDirectionalLight( BOX_TOP, Color( 255, 255, 255 ) )
mdlviewer:SetDirectionalLight( BOX_FRONT, Color( 255, 255, 255 ) )
mdlviewer:SetCamPos( Vector( 50, 0, 5 ) )
mdlviewer:SetLookAt( Vector( 0, 0, 0 ) )
mdlviewer:SetFOV( 60 )
mdlviewer:SetVisible(false)
table.insert(filepanels,mdlviewer)

local editor = vgui.Create( "DTextEntry", treepanel)
editor:SetPos(320,5)
editor:SetSize(treepanel:GetWide()-335,treepanel:GetTall()-40)
editor:SetMultiline(true)
editor:SetVisible(false)
table.insert(filepanels,editor)

local iconview = vgui.Create("Spawnicon",treepanel)
/* iconview:SetPos(320,5)
iconview:SetSize(treepanel:GetWide()-335,treepanel:GetTall()-40) */
iconview:SetPos(405,95)
iconview:SetSize(treepanel:GetWide()-505,treepanel:GetTall()-210)
iconview:SetVisible(false)
table.insert(filepanels,iconview)
	
local function GetName(str,rep)
	str = string.Replace( str, rep, "" )
	return string.Replace( str, "/", "" )
end

function MakeVisible(panel)
	for _,v in ipairs(filepanels) do
		if v == panel then
			if v:GetClassName() == "Label" or v:GetClassName() == "Panel" then
				mdlpanel:SetVisible(true)
				panel:SetVisible(true)
			else panel:SetVisible(true) end
		else v:SetVisible(false) end
	end
end

local function DetectFile(type,dir,parent,icon)
	if type == ".txt" and !string.match(dir, "/data") then return end
	local pFiles = file.Find( dir .. "/*" .. type)
	for _,v in ipairs(pFiles) do
		local filenode = parent:AddNode( GetName(v,type) )
		filenode.FileDir = dir .. "/" .. v
		if type == "" then filenode.IsFile = false
		else 
			filenode.IsFile = true 
			filenode.Icon:SetImage( icon )
		end
		filenode.Name = GetName(v,type)
		filenode.DoClick = function()
			if type == ".vtf" then mdl:SetImage(filenode.FileDir)
				MakeVisible(mdl)
			elseif type == ".mdl" then 
				local prop = ents.Create( "prop_physics")
				prop:SetModel(string.Replace(filenode.FileDir, "../", ""))
				if string.match(filenode.FileDir, "models/player/") then
					function mdlviewer:LayoutEntity(Entity)
						self:RunAnimation();		
					end
					mdlviewer:SetCamPos( Vector( 50, 0, 50 ) )
					mdlviewer:SetLookAt( Vector( 0, 0, 51 ) )
				else
					function mdlviewer:LayoutEntity(Entity)
						Entity:SetAngles( Angle( 0, math.fmod(CurTime(),360)*5, 0) )
					end
					mdlviewer:SetCamPos(prop:OBBCenter()-Vector(prop:BoundingRadius()*2,0,-prop:BoundingRadius()/12))
					mdlviewer:SetLookAt(prop:OBBCenter()-Vector(0,0,-prop:BoundingRadius()/12))
				end
				mdlviewer:SetModel(string.Replace(filenode.FileDir, "../", ""))
				MakeVisible(mdlviewer)
				prop:Remove()
			elseif type == ".mp3" or type == ".wav" then
				if table.Count(sounds) > 0 then sounds[1]:Stop() end
				sounds = {}
				sound = CreateSound(LocalPlayer(),filenode.FileDir)
				table.insert(sounds,sound)
				sound:Play()
			elseif type == ".txt" then
				MakeVisible(editor)
				editor:SetValue(file.Read(string.Replace(filenode.FileDir, "../data/", "")))
			elseif type == ".bsp" then
				MakeVisible(mdl)
				if file.Exists( "../materials/maps/"..filenode.Name.. ".vtf") then
					mdl:SetImage( "maps/"..filenode.Name)
				else mdl:SetImage( "console/gmod_logo")
				end
			elseif type == ".si0" then
				MakeVisible(iconview)
				if file.Exists( "../models/"..string.Replace(string.Replace(filenode.FileDir,"../spawnicons/",""),".si0","")..".mdl") then 
					iconview:SetModel("models/"..string.Replace(string.Replace(filenode.FileDir,"../spawnicons/",""),".si0","")) end
			end
		end
	end
end

local filetypes = {
	{ ".txt", "vgui/spawnmenu/file",
[[All text files in the /data folder are supported!
You can edit existing files as well as create your own by either
selecting the file in the menu or by clicking the New File button.
 
]]},
	{ ".wav", "gui/silkicons/sound",
[[All the sound files with .wav extensions are supported!
To play sound, click on the icon in the menu. 
You can stop and start sounds with the corresponding buttons.
 
]]},
	{ ".mp3", "gui/silkicons/sound",
[[All the sound files with .mp3 extensions are supported!
To play sound, click on the icon in the menu. 
You can stop and start sounds with the corresponding buttons.
 
]]},
	{ ".vtf", "gui/silkicons/palette",
[[All the material files with .vtf extensions are supported!
To view a mateiral, click on the icon in the menu (palettes).
 
]]},
	{ ".mdl", "gui/silkicons/brick_add",
[[All the models with .mdl extensions are supported!
To view a model, click on the icon in the menu (bricks).
 
]]},
	{ ".bsp", "gui/silkicons/world",
[[All the maps with .bsp extensions are supported!
To view a map, click on the icon in the menu (globe).
*Note: This doesn't change maps, it just shows the map icon.
 
]]},
	{".si0","gui/silkicons/user",
[[All the spawnicons with .si0 extensions are supported!
To view a spawnicon, click on the icon in the menu (user).
 
]]},
}

// Thanks to Syranide or whoever made E2 for this!
local function setTree(dir, parent)
	if(dir==nil) then return end
	parent:Clear(true)
	parent.ChildNodes = nil
	local pFolders = file.FindDir(dir .. "/*")
	for k, v in ipairs( pFolders ) do 
		local pFolder = parent:AddNode( v )
		pFolder.FileDir = dir .. "/" .. v
		pFolder.IsFile = false
		pFolder.Name = v
		pFolder.DoClick = function() setTree( pFolder.FileDir, pFolder ) end
	end 
	for _,v in ipairs(filetypes) do DetectFile(v[1],dir,parent,v[2]) end
end

setTree( "..",tree)

local catpanel = vgui.Create( "DPanel",treepanel)
catpanel:SetPos(210,0)
catpanel:SetSize(100,treepanel:GetTall()-10)

function MakeCategory(text,pos)

	local cat = vgui.Create( "DCollapsibleCategory",catpanel)
	cat:SetPos(pos[1],pos[2])
	cat:SetSize(100,200)
	cat:SetLabel(text)

	local catlist = vgui.Create( "DPanelList",cat)
	catlist:SetAutoSize(true)
	catlist:SetPadding(1)
	catlist:SetSpacing(1)
	catlist:EnableVerticalScrollbar(true)
	cat:SetContents(catlist)
	return catlist
end

local soundcat = MakeCategory( "Sound Options",{0,0})
local textcat = MakeCategory( "Text Options",{0,70})
local allwdtypes = MakeCategory( "Supported Files",{0,200-table.Count(filetypes)*5})

function MakeCollapsibleBtn(text,func,cat)
	local btn = vgui.Create( "DButton")
	btn.DoClick = func
	btn:SetText(text)
	cat:AddItem(btn)
end

for _,v in ipairs(filetypes) do MakeCollapsibleBtn(v[1],function() if v[3] then for _,q in ipairs(string.Explode( "\n",v[3])) do LocalPlayer():ChatPrint(q)
	end end end,allwdtypes) end

MakeCollapsibleBtn( "Play Music",function() if sounds[1] then sounds[1]:Play() end end,soundcat)
MakeCollapsibleBtn( "Stop Music",function() if sounds[1] then sounds[1]:Stop() end end,soundcat)

MakeCollapsibleBtn( "New File",function()
	
	local txtframe = vgui.Create( "DFrame")
	txtframe:SetSize(220,55)
	txtframe:Center() 
	txtframe:MakePopup()
	txtframe:SetTitle( "Set File Name (relative to /data)")
	local pswd = vgui.Create( "DTextEntry",txtframe)
	pswd:SetPos(7,30)
	pswd:SetSize(205,20)
	pswd:SetEditable(true)
	pswd.OnEnter = function()
		local str = pswd:GetValue()
		if string.match(str, ".txt") then 
			if string.match(str, "_") then LocalPlayer():ChatPrint( "'_' can't be in the file name!") return txtframe:Close() end
			file.Write(pswd:GetValue(), "")
		else
			if string.match(str, "_") then LocalPlayer():ChatPrint( "'_' can't be in the file name!") return txtframe:Close() end
			file.Write(str.. ".txt", "")
		end
		txtframe:Close()
		mdlpanel:SetVisible(false)
		editor:SetVisible(true)
	end 
end,textcat)

MakeCollapsibleBtn( "Save File",function() 
	if editor:IsVisible() then file.Write(string.Replace(tree:GetSelectedItem().FileDir, "../data/", ""), editor:GetValue())
		LocalPlayer():ChatPrint( "File saved!") 
	else LocalPlayer():ChatPrint( "Must be a text file to save!") end
end,textcat)

MakeCollapsibleBtn( "Delete File",function()
	if editor:IsVisible() then file.Delete(string.Replace(tree:GetSelectedItem().FileDir, "../data/", ""), editor:GetValue())
	tree:GetSelectedItem():SetVisible(false)
	LocalPlayer():ChatPrint("File deleted!")
	editor:SetVisible(false)
	mdlpanel:SetVisible(true)
	mdl:SetVisible(true)
	mdl:SetImage( "console/gmod_logo")
	else LocalPlayer():ChatPrint("Must be a text file to delete!") end
end,textcat)


/************** WEB SURFING ***************/
local webpanel = vgui.Create( "DPanel",sheet)
local html = vgui.Create( "HTML",webpanel)

webpanel:SetPos(0,0)
webpanel:SetSize(sheet:GetWide(),sheet:GetTall())

html:SetPos(0,30)
html:SetSize(webpanel:GetWide()-5,webpanel:GetTall()-65)
html:OpenURL( "http://www.google.com")

local address = vgui.Create( "DTextEntry",webpanel)
address:SetPos(0,1.75)
address:SetSize(200,25)
address:SetText( "http://www.google.com")
address.OnEnter = function()
	if string.match(address:GetValue(), "http://") or string.match(address:GetValue(), "https://") then html:OpenURL(address:GetValue())
	else html:OpenURL( "http://"..address:GetValue()) end
end

local forward = vgui.Create("DImageButton",webpanel)
forward:SetPos(240,1.75)
forward:SetSize(25,25)
forward:SetImage("gad/icons/refresh")
forward:SetToolTip("Go forward a page")
forward.DoClick = function() html:OpenURL("javascript:void( history.back( 1 ) )") end

local back = vgui.Create("DImageButton",webpanel)
back:SetPos(280,1.75)
back:SetSize(25,25)
back:SetImage("gad/icons/refresh")
back:SetToolTip("Go back a page")
back.DoClick = function() html:OpenURL("javascript:void( history.back( 1 ) )") end

local stopbtn = vgui.Create( "DImageButton",webpanel)
stopbtn:SetPos(350,1.75)
stopbtn:SetSize(25,25)
stopbtn:SetImage( "gad/icons/stop")
stopbtn:SetToolTip( "Stop loading")
stopbtn.DoClick = function() html:Stop() end

local refreshbtn = vgui.Create( "DImageButton",webpanel)
refreshbtn:SetPos(390,1.75)
refreshbtn:SetSize(25,25)
refreshbtn:SetImage( "gad/icons/refresh")
refreshbtn:SetToolTip( "Refresh the page")
refreshbtn.DoClick = function() html:Refresh() end

local setbookmark = vgui.Create( "DImageButton",webpanel)
setbookmark:SetImage( "gui/silkicons/star")
setbookmark:SetPos(460,1.75)
setbookmark:SetSize(25,25)
setbookmark:SetToolTip( "Bookmark this page")
setbookmark.DoClick = function()
	if !file.Exists( "gad/bookmarks.txt") then file.Write( "gad/bookmarks.txt", "") end
	local str = file.Read( "gad/bookmarks.txt")
	if string.match(str,address:GetValue()) and str != "" then LocalPlayer():ChatPrint( "You already have this bookmarked!") return end
	local txtframe = vgui.Create( "DFrame")
	txtframe:SetSize(220,55)
	txtframe:Center() 
	txtframe:MakePopup()
	txtframe:SetTitle( "Bookmark Name" )
	txtframe:ShowCloseButton(false)
	local pswd = vgui.Create( "DTextEntry",txtframe)
	pswd:SetPos(7,30)
	pswd:SetSize(205,20)
	pswd:SetEditable(true)
	pswd.OnEnter = function()
		file.Write( "gad/bookmarks.txt",str..address:GetValue().. " "..pswd:GetValue().."\n")
		LocalPlayer():ChatPrint( "Bookmark created!")
		txtframe:Close()
	end 
	
end

local bookmarks = vgui.Create( "DImageButton",webpanel)
bookmarks:SetImage( "gad/icons/bookmark")
bookmarks:SetPos(500,1.75)
bookmarks:SetSize(25,25)
bookmarks:SetToolTip( "Check your bookmarks")
bookmarks.DoClick = function()
	local menu = DermaMenu()
	for _,v in ipairs(string.Explode( "\n",file.Read( "gad/bookmarks.txt"))) do
		local words = string.Explode(" ",v)
		local name = ""
		for p,q in ipairs(words) do if p != 1 then name = name .. " ".. q end end
		if words[1] != "" and name != "" then
		menu:AddOption(name,function()
			if string.match(words[1], "http://") or string.match(words[1], "https://") then html:OpenURL(words[1])
			else html:OpenURL( "http://"..words[1]) end
			address:SetValue(words[1])
		end) end
	end
	menu:Open()
end

alpha = 0
Fade = false
function CreditText(alpha) draw.DrawText("Created by Entoros","ScoreboardText",ScrW()/2,ScrH()/2-100,Color(255,255,255,alpha),1) end

// Thanks mostly goes to Rick Darkoliono for the fade in/out!
if not file.Exists("gad/credits.txt") then
function Credits()
	timer.Simple(6,function() Fade = true end)
	if Fade == false then alpha =  math.Clamp(alpha + 100*FrameTime(),0,200)
	else alpha = math.Clamp(alpha - 100*FrameTime(),0,200) end
	CreditText(alpha)
end
hook.Add("HUDPaint","gadcredits",Credits)

local credits = [[
The creator of the Generic Admin Derma is none other than Entoros!
However, I am very glad for the help/works of many people.

ULX: General layout, finding/sorting of maps/gamemodes
ASSmod: For making a crappy derma that I was inspired to fix
CakeScriptG2: The model panel
Syranide/Expression 2: The tree, pretty much
Shane: For listening to me bitch about programs not working and helping me out with code
Chaotic Cow: For being totally awesome
Rick Darkoliono: Fading credits
]]

timer.Simple(15,function() file.Write("gad/credits.txt",credits) end)
end
	
/************** EVERYTHING ELSE ***************/

local text = vgui.Create( "DTextEntry" ,frame)
local label = vgui.Create( "DLabel" ,frame)
local rcon = vgui.Create( "DCheckBoxLabel" ,frame)
//text:SetPos(260,415)
text:SetPos(framex/2-90,framey-35)
text:SetSize(200,20)
text.OnEnter = function()
	if rcon:GetChecked(true) then LocalPlayer():ConCommand( "gad_rcon "..text:GetValue())
	else LocalPlayer():ConCommand(text:GetValue()) end
	text:SetText( "" ) 
end
label:SetSize(100,30)
label:SetPos(160,410)
label:SetText( "Enter a command:" )
rcon:SetPos(470,418)
rcon:SetText( "Rcon?" )
rcon:SizeToContents()


local resbtn = vgui.Create("DSysButton",frame)
resbtn:SetSize(20,20)
resbtn:SetType("grip")
resbtn:SetPos(frame:GetWide()-25,frame:GetTall()-25)

function Resize(mouse)
	local x,y = frame:GetPos()
	if mouse == true then frame:SetSize(gui.MouseX()-x,gui.MouseY()-y)
	else frame:SetSize(framex,framey) end
	resbtn:SetPos(frame:GetWide()-25,frame:GetTall()-25)
	sheet:SetSize( frame:GetWide()-20 , frame:GetTall() - 75 )
	webpanel:SetSize(sheet:GetWide(),sheet:GetTall())
	html:SetSize(webpanel:GetWide()-5,webpanel:GetTall()-65)
	text:SetPos(frame:GetWide()/2-90,frame:GetTall()-35)
	local textx,texty = string.sub(text:GetPos(),1,3),string.sub(text:GetPos(),3,6)
	label:SetPos(textx-100,frame:GetTall()-40)
	rcon:SetPos(textx+210,frame:GetTall()-32)
end
	
resbtn.Think = function()
	if sheet:GetActiveTab():GetValue() == "Web" then if resbtn:IsDown() == true then Resize(true) end
	else Resize(false) end
end 


sheet:AddSheet( "Server" ,adminpanel, "gui/silkicons/star" ,false,false)
sheet:AddSheet( "Client" ,clientpanel, "gui/silkicons/user" ,false,false)
sheet:AddSheet( "Maps" ,map, "gad/icons/map" ,false,false)
sheet:AddSheet( "Files", treepanel, "gad/icons/page_edit", false,false)
sheet:AddSheet( "Web", webpanel, "gad/icons/application_xp_terminal", false,false)

end end
concommand.Add( "gadmenu" ,panel)